package servlet;


import entity.User;
import service.UserService;
import service.imp.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/list")
public class UserListServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 调用 service 查询所有用户
        List<User> userList = userService.listUsers();
        req.setAttribute("userList", userList);

        req.setAttribute("key1", "req");
        req.getSession().setAttribute("key2","session");
        getServletContext().setAttribute("key3","application");
        req.getRequestDispatcher("user.jsp").forward(req, resp);
    }
}
